package tests;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class GenerateCode {

    public static void main(String[] args) {
        AutoGenerator mpg = new AutoGenerator();
        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        gc.setOutputDir("c://aa"); //代码生成路径
        gc.setAuthor("admin"); //作者
        gc.setOpen(false);
        gc.setBaseResultMap(true);
        gc.setBaseColumnList(true);
        gc.setServiceImplName("PositionService"); //service名
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://14dn981316.51mypc.cn:27759/bs_map?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("root@123");
        mpg.setDataSource(dsc);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setTablePrefix(new String[] { "t_" });// 此处可以修改为您的表前缀
        strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
        strategy.setInclude(new String[] { "t_bs_position" }); // 需要生成的表
        strategy.setEntityTableFieldAnnotationEnable(true);
        mpg.setStrategy(strategy);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.wan");
        pc.setModuleName("out"); //模块名
        pc.setEntity("common");
        pc.setController("controller");
        pc.setServiceImpl("service");
        pc.setMapper("mapper");
        pc.setXml("mapper.mapping");
        mpg.setPackageInfo(pc);

        //模板配置
        TemplateConfig config = new TemplateConfig();
        config.setService(null);
        config.setServiceImpl("template/serviceImpl.java.vm");
        mpg.setTemplate(config);

        mpg.execute();
        System.out.println("生成成功 偶耶  耶耶耶耶耶");
    }
}
